{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f6f47d80",
   "metadata": {},
   "source": [
    "# 周边博物馆、融创乐园搜索"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f95ff0d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7483c018",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2.请求方法：GET\n",
    "# 3.请求的关键字搜索url地址：https://restapi.amap.com/v5/place/text?parameters\n",
    "keyword_url = \"https://restapi.amap.com/v5/place/text?parameters\"\n",
    "\n",
    "# 4.请求的参数（payload）\n",
    "payload = {\n",
    "    \"key\":\"091c69bb3b356e0f0eb237e4e7a62a45\",\n",
    "    \"keywords\":\"博物馆|融创乐园\",\n",
    "    \"city\":\"广州\",\n",
    "    \"extensions\":\"all\",\n",
    "    \"show_fields\":\"photos\"\n",
    "}\n",
    "# 5.发起请求\n",
    "r = requests.get(url=keyword_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4e0376ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'pois': [{'name': '博物馆(公交站)',\n",
       "   'id': 'BV11363916',\n",
       "   'location': '113.592878,23.548216',\n",
       "   'type': '交通设施服务;公交车站;公交车站相关',\n",
       "   'typecode': '150700',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '从化区',\n",
       "   'address': '(停运)从5路延长线;从16路;从20路;从2路;从4路;从5路;从5路长线',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440117'},\n",
       "  {'name': '广州融创乐园',\n",
       "   'id': 'B0GR91RVXO',\n",
       "   'location': '113.240277,23.429549',\n",
       "   'type': '体育休闲服务;休闲场所;游乐场',\n",
       "   'typecode': '080501',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '花都区',\n",
       "   'address': '凤凰北路78号',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440114',\n",
       "   'photos': [{'title': '',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/128a60826e34122bd93d5053a7c1a7a4'},\n",
       "    {'title': '',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/6289b4a56f444e9053163b3c4b858b13'},\n",
       "    {'title': '',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/60bb0080caef7c50ae44d086b328c91a'}]},\n",
       "  {'name': '广东省博物馆',\n",
       "   'id': 'B00140U6L3',\n",
       "   'location': '113.326346,23.114743',\n",
       "   'type': '科教文化服务;博物馆;博物馆',\n",
       "   'typecode': '140100',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '天河区',\n",
       "   'address': '珠江东路2号(大剧院地铁站B口步行290米)',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440106',\n",
       "   'photos': [{'title': '广东省博物馆',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/85fc1a6f904ebab3df6f6346f32aaacb'},\n",
       "    {'title': '广东省博物馆',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/5987170707206a0af7f745d255869f5a'},\n",
       "    {'title': '广东省博物馆',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/416161fddc3472435773e67121d53e2e'}]},\n",
       "  {'name': '广州博物馆(仲元楼展区)',\n",
       "   'id': 'B0FFLCWF9J',\n",
       "   'location': '113.267802,23.137451',\n",
       "   'type': '科教文化服务;博物馆;博物馆|风景名胜;风景名胜相关;旅游景点',\n",
       "   'typecode': '140100|110000',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '越秀区',\n",
       "   'address': '镇海路99号',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440104'},\n",
       "  {'name': '粤剧艺术博物馆',\n",
       "   'id': 'B0FFF2FCXB',\n",
       "   'location': '113.238235,23.115423',\n",
       "   'type': '科教文化服务;博物馆;博物馆',\n",
       "   'typecode': '140100',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '荔湾区',\n",
       "   'address': '恩宁路127号',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440103',\n",
       "   'photos': [{'title': '',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/1031b880f6bc35831533e095f71cb07d'},\n",
       "    {'title': '',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/19706c127e884832a6a8b31ad46bf658'},\n",
       "    {'title': '',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/6a2cb9509ff55abdc53d17b6c895bbf7'}]},\n",
       "  {'name': '声音博物馆',\n",
       "   'id': 'B0FFL02K1A',\n",
       "   'location': '113.271896,23.125377',\n",
       "   'type': '科教文化服务;科教文化场所;科教文化场所',\n",
       "   'typecode': '140000',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '越秀区',\n",
       "   'address': '中山四路长兴里3号(农讲所地铁站D口步行380米)',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440104'},\n",
       "  {'name': '广州博物馆(镇海楼展区)',\n",
       "   'id': 'B00140T14E',\n",
       "   'location': '113.265698,23.137723',\n",
       "   'type': '科教文化服务;博物馆;博物馆',\n",
       "   'typecode': '140100',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '越秀区',\n",
       "   'address': '解放北路988号',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440104',\n",
       "   'photos': [{'title': '',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/763ced1ef37e15907ae0acf4cc70cc61'},\n",
       "    {'title': '',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/e257512002ff54686b9e30f24144a2a6'},\n",
       "    {'title': '',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/c652dd49bf04c33ba6e0391b62f5f68e'}]},\n",
       "  {'name': '从化博物馆(公交站)',\n",
       "   'id': 'BV11228252',\n",
       "   'location': '113.592819,23.548147',\n",
       "   'type': '交通设施服务;公交车站;公交车站相关',\n",
       "   'typecode': '150700',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '从化区',\n",
       "   'address': '从夜1路',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440117'},\n",
       "  {'name': '广州艺术博物院',\n",
       "   'id': 'B00140AI11',\n",
       "   'location': '113.280655,23.142858',\n",
       "   'type': '科教文化服务;博物馆;博物馆',\n",
       "   'typecode': '140100',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '越秀区',\n",
       "   'address': '麓湖路13号',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440104',\n",
       "   'photos': [{'title': '广州艺术博物院',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/c45ea2372107b9b0c084307616036625'},\n",
       "    {'title': '广州艺术博物院',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/e6504e4962cca134c7049c30a43863cd'},\n",
       "    {'title': '',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/54fcd3bfc0cd1305c623e4376b0b3017'}]},\n",
       "  {'name': '广州融创乐园停车场(入口)',\n",
       "   'id': 'B0H2Z7ALIT',\n",
       "   'location': '113.240478,23.427478',\n",
       "   'type': '交通设施服务;停车场;停车场入口',\n",
       "   'typecode': '150907',\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '花都区',\n",
       "   'address': '平步大道东与花都大道交叉口东北340米',\n",
       "   'pcode': '440000',\n",
       "   'citycode': '020',\n",
       "   'adcode': '440114'}],\n",
       " 'count': '10'}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "05bbda30",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "01d925e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>id</th>\n",
       "      <th>location</th>\n",
       "      <th>type</th>\n",
       "      <th>typecode</th>\n",
       "      <th>pname</th>\n",
       "      <th>cityname</th>\n",
       "      <th>adname</th>\n",
       "      <th>address</th>\n",
       "      <th>pcode</th>\n",
       "      <th>citycode</th>\n",
       "      <th>adcode</th>\n",
       "      <th>photos</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>博物馆(公交站)</td>\n",
       "      <td>BV11363916</td>\n",
       "      <td>113.592878,23.548216</td>\n",
       "      <td>交通设施服务;公交车站;公交车站相关</td>\n",
       "      <td>150700</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "      <td>从化区</td>\n",
       "      <td>(停运)从5路延长线;从16路;从20路;从2路;从4路;从5路;从5路长线</td>\n",
       "      <td>440000</td>\n",
       "      <td>020</td>\n",
       "      <td>440117</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>广州融创乐园</td>\n",
       "      <td>B0GR91RVXO</td>\n",
       "      <td>113.240277,23.429549</td>\n",
       "      <td>体育休闲服务;休闲场所;游乐场</td>\n",
       "      <td>080501</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "      <td>花都区</td>\n",
       "      <td>凤凰北路78号</td>\n",
       "      <td>440000</td>\n",
       "      <td>020</td>\n",
       "      <td>440114</td>\n",
       "      <td>[{'title': '', 'url': 'http://store.is.autonav...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>广东省博物馆</td>\n",
       "      <td>B00140U6L3</td>\n",
       "      <td>113.326346,23.114743</td>\n",
       "      <td>科教文化服务;博物馆;博物馆</td>\n",
       "      <td>140100</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "      <td>天河区</td>\n",
       "      <td>珠江东路2号(大剧院地铁站B口步行290米)</td>\n",
       "      <td>440000</td>\n",
       "      <td>020</td>\n",
       "      <td>440106</td>\n",
       "      <td>[{'title': '广东省博物馆', 'url': 'http://store.is.a...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>广州博物馆(仲元楼展区)</td>\n",
       "      <td>B0FFLCWF9J</td>\n",
       "      <td>113.267802,23.137451</td>\n",
       "      <td>科教文化服务;博物馆;博物馆|风景名胜;风景名胜相关;旅游景点</td>\n",
       "      <td>140100|110000</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "      <td>越秀区</td>\n",
       "      <td>镇海路99号</td>\n",
       "      <td>440000</td>\n",
       "      <td>020</td>\n",
       "      <td>440104</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>粤剧艺术博物馆</td>\n",
       "      <td>B0FFF2FCXB</td>\n",
       "      <td>113.238235,23.115423</td>\n",
       "      <td>科教文化服务;博物馆;博物馆</td>\n",
       "      <td>140100</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "      <td>荔湾区</td>\n",
       "      <td>恩宁路127号</td>\n",
       "      <td>440000</td>\n",
       "      <td>020</td>\n",
       "      <td>440103</td>\n",
       "      <td>[{'title': '', 'url': 'http://store.is.autonav...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>声音博物馆</td>\n",
       "      <td>B0FFL02K1A</td>\n",
       "      <td>113.271896,23.125377</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "      <td>140000</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "      <td>越秀区</td>\n",
       "      <td>中山四路长兴里3号(农讲所地铁站D口步行380米)</td>\n",
       "      <td>440000</td>\n",
       "      <td>020</td>\n",
       "      <td>440104</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>广州博物馆(镇海楼展区)</td>\n",
       "      <td>B00140T14E</td>\n",
       "      <td>113.265698,23.137723</td>\n",
       "      <td>科教文化服务;博物馆;博物馆</td>\n",
       "      <td>140100</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "      <td>越秀区</td>\n",
       "      <td>解放北路988号</td>\n",
       "      <td>440000</td>\n",
       "      <td>020</td>\n",
       "      <td>440104</td>\n",
       "      <td>[{'title': '', 'url': 'http://store.is.autonav...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>从化博物馆(公交站)</td>\n",
       "      <td>BV11228252</td>\n",
       "      <td>113.592819,23.548147</td>\n",
       "      <td>交通设施服务;公交车站;公交车站相关</td>\n",
       "      <td>150700</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "      <td>从化区</td>\n",
       "      <td>从夜1路</td>\n",
       "      <td>440000</td>\n",
       "      <td>020</td>\n",
       "      <td>440117</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>广州艺术博物院</td>\n",
       "      <td>B00140AI11</td>\n",
       "      <td>113.280655,23.142858</td>\n",
       "      <td>科教文化服务;博物馆;博物馆</td>\n",
       "      <td>140100</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "      <td>越秀区</td>\n",
       "      <td>麓湖路13号</td>\n",
       "      <td>440000</td>\n",
       "      <td>020</td>\n",
       "      <td>440104</td>\n",
       "      <td>[{'title': '广州艺术博物院', 'url': 'http://store.is....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>广州融创乐园停车场(入口)</td>\n",
       "      <td>B0H2Z7ALIT</td>\n",
       "      <td>113.240478,23.427478</td>\n",
       "      <td>交通设施服务;停车场;停车场入口</td>\n",
       "      <td>150907</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "      <td>花都区</td>\n",
       "      <td>平步大道东与花都大道交叉口东北340米</td>\n",
       "      <td>440000</td>\n",
       "      <td>020</td>\n",
       "      <td>440114</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            name          id              location  \\\n",
       "0       博物馆(公交站)  BV11363916  113.592878,23.548216   \n",
       "1         广州融创乐园  B0GR91RVXO  113.240277,23.429549   \n",
       "2         广东省博物馆  B00140U6L3  113.326346,23.114743   \n",
       "3   广州博物馆(仲元楼展区)  B0FFLCWF9J  113.267802,23.137451   \n",
       "4        粤剧艺术博物馆  B0FFF2FCXB  113.238235,23.115423   \n",
       "5          声音博物馆  B0FFL02K1A  113.271896,23.125377   \n",
       "6   广州博物馆(镇海楼展区)  B00140T14E  113.265698,23.137723   \n",
       "7     从化博物馆(公交站)  BV11228252  113.592819,23.548147   \n",
       "8        广州艺术博物院  B00140AI11  113.280655,23.142858   \n",
       "9  广州融创乐园停车场(入口)  B0H2Z7ALIT  113.240478,23.427478   \n",
       "\n",
       "                              type       typecode pname cityname adname  \\\n",
       "0               交通设施服务;公交车站;公交车站相关         150700   广东省      广州市    从化区   \n",
       "1                  体育休闲服务;休闲场所;游乐场         080501   广东省      广州市    花都区   \n",
       "2                   科教文化服务;博物馆;博物馆         140100   广东省      广州市    天河区   \n",
       "3  科教文化服务;博物馆;博物馆|风景名胜;风景名胜相关;旅游景点  140100|110000   广东省      广州市    越秀区   \n",
       "4                   科教文化服务;博物馆;博物馆         140100   广东省      广州市    荔湾区   \n",
       "5             科教文化服务;科教文化场所;科教文化场所         140000   广东省      广州市    越秀区   \n",
       "6                   科教文化服务;博物馆;博物馆         140100   广东省      广州市    越秀区   \n",
       "7               交通设施服务;公交车站;公交车站相关         150700   广东省      广州市    从化区   \n",
       "8                   科教文化服务;博物馆;博物馆         140100   广东省      广州市    越秀区   \n",
       "9                 交通设施服务;停车场;停车场入口         150907   广东省      广州市    花都区   \n",
       "\n",
       "                                  address   pcode citycode  adcode  \\\n",
       "0  (停运)从5路延长线;从16路;从20路;从2路;从4路;从5路;从5路长线  440000      020  440117   \n",
       "1                                 凤凰北路78号  440000      020  440114   \n",
       "2                  珠江东路2号(大剧院地铁站B口步行290米)  440000      020  440106   \n",
       "3                                  镇海路99号  440000      020  440104   \n",
       "4                                 恩宁路127号  440000      020  440103   \n",
       "5               中山四路长兴里3号(农讲所地铁站D口步行380米)  440000      020  440104   \n",
       "6                                解放北路988号  440000      020  440104   \n",
       "7                                    从夜1路  440000      020  440117   \n",
       "8                                  麓湖路13号  440000      020  440104   \n",
       "9                     平步大道东与花都大道交叉口东北340米  440000      020  440114   \n",
       "\n",
       "                                              photos  \n",
       "0                                                NaN  \n",
       "1  [{'title': '', 'url': 'http://store.is.autonav...  \n",
       "2  [{'title': '广东省博物馆', 'url': 'http://store.is.a...  \n",
       "3                                                NaN  \n",
       "4  [{'title': '', 'url': 'http://store.is.autonav...  \n",
       "5                                                NaN  \n",
       "6  [{'title': '', 'url': 'http://store.is.autonav...  \n",
       "7                                                NaN  \n",
       "8  [{'title': '广州艺术博物院', 'url': 'http://store.is....  \n",
       "9                                                NaN  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.json_normalize(r.json()['pois'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05556ceb",
   "metadata": {},
   "source": [
    "# 文创产品以及经典等识别--通用场景识别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "62efe0a2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.3c966d6a195effdfa8fbbecf584e8fb9.315360000.1972733557.282335-25863395', 'expires_in': 2592000, 'session_key': '9mzdAqQKcP/pUNaV4hEHYLdhXw4lOUvYSpcbEOJYK6EVKi4auKwaRr5SWW4xOCudTaPkrYSrjwLLkmfqZ8C6d/sgw1X52w==', 'access_token': '24.9f19d92dd2c0195cd53eaa52b98fe017.2592000.1659965557.282335-25863395', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_multi_ object_detect wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'session_secret': 'be17749a103abfb10a6679ff014bd52e'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?'\n",
    "payload = {\n",
    "    'grant_type':'client_credentials',\n",
    "    'client_id':'gajHslLdwMXiHLNGy4Sp5P5k',\n",
    "    'client_secret':'U5l0wGvtvp8x2Getl9q0PEEc9OVBYpYB'\n",
    "}\n",
    "response = requests.get(host,params=payload)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "f623b6e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.9f19d92dd2c0195cd53eaa52b98fe017.2592000.1659965557.282335-25863395'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "haixin_AT = response.json()['access_token']\n",
    "haixin_AT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "38786bfc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'error_code': 18, 'error_msg': 'Open api qps request limit reached'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "通用物体和场景识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1. 图片文件准备\n",
    "f = open('sm.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2.酬载参数准备\n",
    "payload = {\n",
    "    'access_token':haixin_AT,\n",
    "    'url':\"https://img.zcool.cn/community/01502656878f6c6ac7251bb643049a.jpg@2o.jpg\",\n",
    "    'baike_num':5\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e89acea",
   "metadata": {},
   "source": [
    "# 红酒识别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "9b358962",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result': {'wineNameCn': 'Scharzhofberger Spätlese Mosel-Saar-Ruwer Riesling', 'hasdetail': 0}, 'log_id': 1545763019938625312}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "红酒识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/redwine\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1. 图片文件准备\n",
    "f = open('jiu.png', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2.酬载参数准备\n",
    "payload = {\n",
    "    'access_token':haixin_AT,\n",
    "    'image':img,\n",
    "    'baike_num':5\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a09ece5",
   "metadata": {},
   "source": [
    "# 天气"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "0cf31504",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "# 2.请求方法：GET\n",
    "# 3.请求的天气url地址：https://devapi.qweather.com/v7/weather/now?location=101010100&key=你的KEY\n",
    "keyword_url = \"https://devapi.qweather.com/v7/weather/now?location=113.678280,23.628439&key=6a715e671a3d4fff8af065e441817ae8\"\n",
    "\n",
    "# 4.发起请求\n",
    "r = requests.get(url=keyword_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "5e476f1e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'code': '200',\n",
       " 'updateTime': '2022-07-09T21:37+08:00',\n",
       " 'fxLink': 'http://hfx.link/3hc1',\n",
       " 'now': {'obsTime': '2022-07-09T21:24+08:00',\n",
       "  'temp': '29',\n",
       "  'feelsLike': '31',\n",
       "  'icon': '151',\n",
       "  'text': '多云',\n",
       "  'wind360': '180',\n",
       "  'windDir': '南风',\n",
       "  'windScale': '3',\n",
       "  'windSpeed': '16',\n",
       "  'humidity': '77',\n",
       "  'precip': '0.0',\n",
       "  'pressure': '989',\n",
       "  'vis': '30',\n",
       "  'cloud': '91',\n",
       "  'dew': '25'},\n",
       " 'refer': {'sources': ['QWeather', 'NMC', 'ECMWF'],\n",
       "  'license': ['no commercial use']}}"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
